<?php

namespace App\Http\Controllers\Api\v1;

use App\common;
use App\Http\Controllers\Controller;
use App\Logic\RegisterLogic;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;

class MangerLoginController extends Controller
{

    /**
     * @name wl
     * @function 多字段登录并判断状态
     * @param Request $request
     */
    public function attemptLogin(Request $request)
    {
        try {
            $vaLiDate = $this->validate($request, [
                'username' => 'required|string|unique:zfm_users|max:20',
                'password' => 'required|string|min:8',
            ]);
            $registerLogic = RegisterLogic::loginMessage($vaLiDate);//登录逻辑
            if ($registerLogic) return common::success(20000, $registerLogic, "登录成功");
        } catch (ValidationException $validationException) {
            $error = $validationException->errors();
            return common::fail('', $error, "数据异常");
        }
    }
}
